(:
  A procedure to find threading information finding the first ancestor given 
  parentid and id facetnames 
:)
declare boundary-space strip;
import module namespace
    jj = "http://kumquat.emse.fr/utilitaires"
    at "jjutils.xq" ;
declare variable $doc := doc($arguments[1]);
declare variable $items := $doc/display/item;
 
<display>{
for $item in $items
return
<item>{
		for $info in $item/info where $info/@name != "num" return $info,
		  <info name="N">{1 + count($item/preceding-sibling::*[jj:get-info(.,"user")=jj:get-info($item,"user")])}</info>
  }</item>
}</display>
